home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 17 / MacFormat 17 (Spain) / MacFormat 17.bin / DATABASE / SHARED.DIR / 01003.ls < prev    next >
Encoding:
Text File  |  1996-03-14  |  12.8 KB  |  422 lines

  1. on BatchProcess world, startnum
  2.   put world
  3.   set the text of field ("cuttingindex" & world) to EMPTY
  4.   set the text of field "BatchErrors" to EMPTY
  5.   BatchParse(world, startnum)
  6. end
  7.  
  8. on ProcessPerson fname
  9.   cursor(4)
  10.   if ParseFile(fname & ".SCR") = -1 then
  11.     alert("problem with script file")
  12.     cursor(0)
  13.     go(2)
  14.     abort()
  15.   end if
  16.   if MakeIndex(fname & ".TXT") = -1 then
  17.     alert("problem with text cuttings file")
  18.     cursor(0)
  19.     go(2)
  20.     abort()
  21.   end if
  22.   cursor(0)
  23. end
  24.  
  25. on BatchParse world, startnum
  26.   global gMakerName, mpath, gMakerNum
  27.   set mpath to the pathName & world & ":"
  28.   set fileList to []
  29.   set num to the number of lines in field "filenames"
  30.   repeat with i = 1 to num
  31.     set n to line i of field "filenames"
  32.     if notEmpty(n) then
  33.       add(fileList, n)
  34.     end if
  35.   end repeat
  36.   set num to the number of lines in field "filenames2"
  37.   repeat with i = 1 to num
  38.     set n to line i of field "filenames2"
  39.     if notEmpty(n) then
  40.       add(fileList, n)
  41.     end if
  42.   end repeat
  43.   set num to count(fileList)
  44.   set tmperrlist to []
  45.   repeat with i = startnum to num
  46.     set fname to getAt(fileList, i)
  47.     put "batch parsing " && fname
  48.     set gMakerNum to NameToNum(fname)
  49.     set gMakerName to fname
  50.     set err to ParseFile(fname & ".scr")
  51.     if err = -1 then
  52.       add(tmperrlist, fname)
  53.     end if
  54.     set the itemDelimiter to "."
  55.     set fname to item 1 of fname
  56.     set the itemDelimiter to ","
  57.     set err to MakeIndex(fname & ".TXT")
  58.     if err = -1 then
  59.       add(tmperrlist, fname)
  60.     end if
  61.   end repeat
  62.   set num to count(tmperrlist)
  63.   put "Errors in " && num && "script files:"
  64.   set tmpnum to the number of lines in field "BatchErrors" + 1
  65.   put "Errors in " && num && "script files:" into line tmpnum of field "BatchErrors"
  66.   repeat with i = 1 to num
  67.     put i & ":" && getAt(tmperrlist, i)
  68.     set tmpnum to the number of lines in field "BatchErrors" + 1
  69.     put i & ":" && getAt(tmperrlist, i) into line tmpnum of field "BatchErrors"
  70.   end repeat
  71. end
  72.  
  73. on ParseFile name
  74.   global fileObj, txt, mpath
  75.   if the paramCount = 0 then
  76.     set fileObj to FileIO(mnew, "?read", "TEXT")
  77.   else
  78.     set fileObj to FileIO(mnew, "read", mpath & name)
  79.   end if
  80.   if not objectp(fileObj) then
  81.     alert("error opening file" && name)
  82.     exit
  83.   else
  84.     set txt to fileObj(mReadFile)
  85.     fileObj(mdispose)
  86.     set err to Parse()
  87.     if err = -1 then
  88.       return -1
  89.       exit
  90.     end if
  91.   end if
  92.   put "saving..."
  93.   saveNewParse()
  94.   return 0
  95. end
  96.  
  97. on Parse
  98.   global txt, gChapters, gArticles, gCaptions, gTitles, gDates, gName, gTotalChapters, gnuggets
  99.   set debug to 0
  100.   if debug then
  101.     set the text of field "parsed" to EMPTY
  102.   end if
  103.   set gChapters to []
  104.   set gArticles to []
  105.   set tmplist to []
  106.   set gCaptions to EMPTY
  107.   set gTitles to EMPTY
  108.   set tmptitles to EMPTY
  109.   set tmpcaptions to EMPTY
  110.   set gDates to []
  111.   set tmpdates to []
  112.   set gnuggets to EMPTY
  113.   set captionText to EMPTY
  114.   set gName to EMPTY
  115.   set num to 1
  116.   set totalnum to the number of lines in txt
  117.   set chap to 0
  118.   set inNuggets to 0
  119.   set article to 0
  120.   repeat with num = 1 to totalnum
  121.     set ln to line num of txt
  122.     if not notEmpty(ln) then
  123.       next repeat
  124.     end if
  125.     if chap = 0 then
  126.       if char 1 of ln <> "1" then
  127.         next repeat
  128.       else
  129.         set chap to 1
  130.       end if
  131.     end if
  132.     if chap = 1 then
  133.       if ln contains "Name" then
  134.         set num to num + 1
  135.         set gName to word the number of words in line num of txt of line num of txt
  136.       end if
  137.     end if
  138.     if char 1 of ln <> string(chap) then
  139.       if inNuggets then
  140.         put "error in the nuggets."
  141.         return -1
  142.         exit
  143.       end if
  144.       if debug then
  145.         put "------------------------------------------" into line the number of lines in field "parsed" + 1 of field "parsed"
  146.       end if
  147.       set chap to chap + 1
  148.       if chap > 2 then
  149.         add(gArticles, tmplist)
  150.         set the itemDelimiter to "@"
  151.         set capnum to the number of items in gCaptions
  152.         if gCaptions = EMPTY then
  153.           set gCaptions to "@" & tmpcaptions
  154.         else
  155.           put tmpcaptions into item capnum + 1 of gCaptions
  156.         end if
  157.         set the itemDelimiter to ","
  158.         set the itemDelimiter to "@"
  159.         set titnum to the number of items in gTitles
  160.         if gTitles = EMPTY then
  161.           set gTitles to "@" & tmptitles
  162.         else
  163.           put tmptitles into item titnum + 1 of gTitles
  164.         end if
  165.         set the itemDelimiter to ","
  166.         add(gDates, tmpdates)
  167.       end if
  168.       if not (ln contains "nuggets") then
  169.         add(gChapters, ln)
  170.       else
  171.         set inNuggets to 1
  172.       end if
  173.       set tmplist to []
  174.       set tmptitles to []
  175.       set tmpcaptions to EMPTY
  176.       set tmpdates to []
  177.       if debug then
  178.         put "Chapter:" && ln into line the number of lines in field "parsed" + 1 of field "parsed"
  179.       end if
  180.       set num to num + 1
  181.       repeat while not notEmpty(line num of txt)
  182.         set num to num + 1
  183.       end repeat
  184.       set oldchap to chap
  185.       set chap to charToNum(char 1 of word 1 of line num of txt) - 48
  186.       if not inNuggets and (((chap - oldchap) > 5) or (oldchap > chap) or (chap < 0)) then
  187.         put "error in " && oldchap & "." & article
  188.         return -1
  189.         exit
  190.       end if
  191.       put gName && "chap = " && chap
  192.       set num to num - 1
  193.       set article to 0
  194.       next repeat
  195.     end if
  196.     if inNuggets = 1 then
  197.       set article to article + 1
  198.       delete word 1 of ln
  199.       set the itemDelimiter to "#"
  200.       set tmpnugnum to the number of items in gnuggets
  201.       if gnuggets = EMPTY then
  202.         set gnuggets to ln
  203.       else
  204.         put ln into item tmpnugnum + 1 of gnuggets
  205.       end if
  206.       set the itemDelimiter to ","
  207.       set num to num + 1
  208.       if debug then
  209.         put chap & "." & article && ln && line num of txt into line the number of lines in field "parsed" + 1 of field "parsed"
  210.       end if
  211.       next repeat
  212.     end if
  213.     if (ln contains "audio") or (ln contains "sound") or (ln contains "bbc") then
  214.       set article to article + 1
  215.       add(tmplist, article, "sound")
  216.       set num to num + 1
  217.       set num to SkipToNumber(txt, chap, article, num)
  218.       if num = -1 then
  219.         return -1
  220.         exit
  221.       end if
  222.       if debug then
  223.         put chap & "." & article && "Sound:" into line the number of lines in field "parsed" + 1 of field "parsed"
  224.       end if
  225.       if not (line num of txt contains "caption") then
  226.         put "error: " && chap & "." & article && "should have a caption"
  227.         return -1
  228.         exit
  229.       end if
  230.       set num to num + 1
  231.       if debug then
  232.         put chap & "." & article & " Caption:" && line num of txt into line the number of lines in field "parsed" + 1 of field "parsed"
  233.       end if
  234.       set the itemDelimiter to "#"
  235.       put line num of txt into item article of tmpcaptions
  236.       set the itemDelimiter to ","
  237.       next repeat
  238.     end if
  239.     if (ln contains "pic") or (ln contains "photo") then
  240.       set article to article + 1
  241.       add(tmplist, article, "pic")
  242.       set num to num + 1
  243.       set num to SkipToNumber(txt, chap, article, num)
  244.       if num = -1 then
  245.         return -1
  246.         exit
  247.       end if
  248.       if debug then
  249.         put chap & "." & article && "Pic:" into line the number of lines in field "parsed" + 1 of field "parsed"
  250.       end if
  251.       if not (line num of txt contains "caption") then
  252.         put "error: " && chap & "." & article && "should have a caption"
  253.         return -1
  254.         exit
  255.       end if
  256.       set num to num + 1
  257.       if debug then
  258.         put chap & "." & article & " Caption:" && line num of txt into line the number of lines in field "parsed" + 1 of field "parsed"
  259.       end if
  260.       set the itemDelimiter to "#"
  261.       put line num of txt into item article of tmpcaptions
  262.       set the itemDelimiter to ","
  263.       next repeat
  264.     end if
  265.     if (ln contains "movie") or (ln contains "video") or (ln contains "graphic") or (ln contains "footage") or (ln contains "film") or (ln contains "animation") then
  266.       set article to article + 1
  267.       if (ln contains "graphic") or (ln contains "animation") then
  268.         add(tmplist, article, "animation")
  269.       else
  270.         add(tmplist, article, "movie")
  271.       end if
  272.       set num to num + 1
  273.       set num to SkipToNumber(txt, chap, article, num)
  274.       if num = -1 then
  275.         return -1
  276.         exit
  277.       end if
  278.       if debug then
  279.         put chap & "." & article && "Movie:" && line num of txt into line the number of lines in field "parsed" + 1 of field "parsed"
  280.       end if
  281.       if not (line num of txt contains "caption") then
  282.         put "error: " && chap & "." & article && "should have a caption"
  283.         return -1
  284.         exit
  285.       end if
  286.       set num to num + 1
  287.       if debug then
  288.         put chap & "." & article & " Caption:" && line num of txt into line the number of lines in field "parsed" + 1 of field "parsed"
  289.       end if
  290.       set the itemDelimiter to "#"
  291.       put line num of txt into item article of tmpcaptions
  292.       set the itemDelimiter to ","
  293.       next repeat
  294.     end if
  295.     if (ln contains "partwork") and (chap > 1) then
  296.       set article to article + 1
  297.       add(tmplist, article, "partwork")
  298.       set num to num + 1
  299.       set num to SkipToNumber(txt, chap, article, num)
  300.       if num = -1 then
  301.         return -1
  302.         exit
  303.       end if
  304.       if debug then
  305.         put chap & "." & article && "Partwork2:" && line num of txt into line the number of lines in field "parsed" + 1 of field "parsed"
  306.       end if
  307.       if not (line num of txt contains "caption") then
  308.         put "error: " && chap & "." & article && "should have a caption"
  309.         return -1
  310.         exit
  311.       end if
  312.       set num to num + 1
  313.       if debug then
  314.         put chap & "." & article & " Caption:" && line num of txt into line the number of lines in field "parsed" + 1 of field "parsed"
  315.       end if
  316.       set the itemDelimiter to "#"
  317.       put line num of txt into item article of tmpcaptions
  318.       set the itemDelimiter to ","
  319.       add(tmpdates, article, " ")
  320.       next repeat
  321.     end if
  322.     if ln contains "cutting" then
  323.       set article to article + 1
  324.       add(tmplist, article, "cutting")
  325.       if debug then
  326.         put chap & "." & article && "Cutting:" into line the number of lines in field "parsed" + 1 of field "parsed"
  327.       end if
  328.       set num to num + 1
  329.       set num to SkipToNumber(txt, chap, article, num)
  330.       if num = -1 then
  331.         return -1
  332.         exit
  333.       end if
  334.       if notEmpty(line num + 1 of txt) then
  335.         set num to num + 1
  336.       else
  337.         delete word 1 of line num of txt
  338.       end if
  339.       if debug then
  340.         put chap & "." & article && "Headline:" && line num of txt into line the number of lines in field "parsed" + 1 of field "parsed"
  341.       end if
  342.       set the itemDelimiter to "#"
  343.       put line num of txt into item article of tmptitles
  344.       set the itemDelimiter to ","
  345.       set num to num + 1
  346.       set num to SkipToNumber(txt, chap, article, num)
  347.       if num = -1 then
  348.         return -1
  349.         exit
  350.       end if
  351.       if notEmpty(line num + 1 of txt) then
  352.         set num to num + 1
  353.       else
  354.         delete word 1 of line num of txt
  355.       end if
  356.       if debug then
  357.         put chap & "." & article && "Date:" && line num of txt into line the number of lines in field "parsed" + 1 of field "parsed"
  358.       end if
  359.       add(tmpdates, article, line num of txt)
  360.       set num to num + 1
  361.       set num to SkipToNumber(txt, chap, article, num)
  362.       if num = -1 then
  363.         return -1
  364.         exit
  365.       end if
  366.       if not (line num of txt contains "caption") then
  367.         put "error: " && chap & "." & article && "should have a caption"
  368.         return -1
  369.         exit
  370.       end if
  371.       set num to num + 1
  372.       if debug then
  373.         put chap & "." & article && "Caption:" && line num of txt into line the number of lines in field "parsed" + 1 of field "parsed"
  374.       end if
  375.       set the itemDelimiter to "#"
  376.       put line num of txt into item article of tmpcaptions
  377.       set the itemDelimiter to ","
  378.       next repeat
  379.     end if
  380.     set article to article + 1
  381.     delete word 1 of ln
  382.     add(tmplist, ln)
  383.     set num to num + 1
  384.     if debug then
  385.       put chap & "." & article && ln && line num of txt into line the number of lines in field "parsed" + 1 of field "parsed"
  386.     end if
  387.   end repeat
  388.   addAt(gChapters, 1, "INTRO")
  389.   addAt(gArticles, 1, ["Partwork"])
  390.   addAt(gDates, 1, [])
  391.   set gTotalChapters to count(gChapters)
  392.   return 0
  393. end
  394.  
  395. on notEmpty str
  396.   set num to the number of chars in str
  397.   if num > 5 then
  398.     return 1
  399.   end if
  400.   set alphanum to "abcdefghijklmnopqrstuvwxyz1234567890!@$%^&*()-=_+{}[];:'\|,.<>/?`~"
  401.   repeat with j = 1 to num
  402.     if alphanum contains char j of str then
  403.       return 1
  404.       exit repeat
  405.     end if
  406.   end repeat
  407.   return 0
  408. end
  409.  
  410. on SkipToNumber txt, chap, art, num
  411.   set start to num
  412.   repeat while char 1 of word 1 of line num of txt <> string(chap)
  413.     set num to num + 1
  414.     if (num - start) > 5 then
  415.       put "Error in " && chap & "." & art
  416.       return -1
  417.       exit
  418.     end if
  419.   end repeat
  420.   return num
  421. end
  422.